/*
 * @Author: your name
 * @Date: 2021-08-30 11:23:08
 * @LastEditTime: 2021-08-30 12:03:21
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \briup\5-javascript\day06\5-数组的数据类型转换.js
 */

//[] ---->String
//[] ---->boolean
console.log(Boolean(null)); //false 空指针，栈中没值
console.log(Boolean([])); //true
console.log(!!([100, 200])); //true

//1.Array.prototype.toString()
//对数组成员依次进行循环遍历
//item.toString(),item.toString(),item.toString()
var arr = [100, 200, { name: 'zs' }];
console.log(arr.toString());
console.log(['hello', 'world'].toString());

var arr2 = [100, true, 'hello', {},
    [1, 2, 3],
    function() {}
];
console.log(arr2.toString());

//2.直接console.log
console.log(arr, arr2);

//3.显示的String() +'' 强制数据类型转换===>arr.toString()
console.log(String(arr));
console.log(arr + '');

//4.使用Array.prototype里的实例方法join()
//应用场景：纯净的数据环境 指定连接符
var str1 = arr.join(); //,
var str2 = arr.join('@'); //@
var str3 = arr.join('*'); //*
console.log(str1, str2, str3);

//5.arr--->string 维持数据内容、层次结构、数据类型
//数组变字符串，字符串变数组   叫做序列化和反序列化
//JSON.stringify()  数组、对象变字符串
//JSON.parse()      字符串变数组、对象
//JSON不处理函数，只处理数据
var str = JSON.stringify(arr2);
console.log(str);
//后台传递字符串过来
var str1 = "{\"name\":\"zs\",\"age\":100}";
var str2 = "[100,200,300]";
r1 = JSON.parse(str1);
r2 = JSON.parse(atr2);
console.log(r1);
console.log(r2);
if (Array.isArray(r1)) {
    console.log('数组类型');
} else {
    console.log('对象类型');
}